package com.sharemarking.wa.platform.mapper;

import com.sharemarking.wa.common.entity.Dict;
import com.sharemarking.wa.platform.dto.ConfigInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface DictMapper {

    @Cacheable("dict")
    @Select("SELECT * FROM sys_dict d WHERE d.value = #{value} AND d.type = #{type} AND d.del_flag = 0")
    public Dict getDict(@Param("value") String value, @Param("type") String type);

    //@Cacheable("dictLabel")
    @Select("SELECT d.label FROM sys_dict d WHERE d.value = #{value} AND d.type = #{type} AND d.del_flag = 0")
    public String getDictLabel(@Param("value") String value, @Param("type") String type);

    @Cacheable("dictValue")
    @Select("SELECT d.value FROM sys_dict d WHERE d.label = #{label} AND d.type = #{type} AND d.del_flag = 0")
    public String getDictValue(@Param("label") String label, @Param("type") String type);

    //	@Cacheable("dictList")
    @Select("SELECT * FROM sys_dict d WHERE d.type = #{type} AND d.del_flag = 0")
    public List<Dict> findAllByTypeAndValue(@Param("type") String type);

    @Select("SELECT label FROM sys_dict WHERE type = #{type} AND del_flag = 0")
    public List<String> getDictLabelByType(String type);

    @Select("SELECT * FROM (\n" +
            "(SELECT label AS serviceMobile FROM sys_dict WHERE type = 'serviceMobile')AS serviceMobile ,\n" +
            "\n" +
            "(SELECT label AS serviceTime FROM sys_dict WHERE type = 'serviceTime') AS serviceTime,\n" +
            "\n" +
            "(SELECT label AS logo FROM sys_dict WHERE type = 'logo') AS logo,\n" +
            "\n" +
            "(SELECT label AS version FROM sys_dict WHERE type = 'version') AS version,\n" +
            "\n" +
            "(SELECT label AS agreementContent FROM sys_dict WHERE type = 'agreementContent') AS agreementContent )\n" +
            "\n")
    ConfigInfo getConfigInfo();
}
